var ColliderRange = cc.Class({
  extends: cc.Component,

  properties: () => ({
    prefabManager: {
      default: null,
      type: require("PrefabManager")
    },
    game: {
      default: null,
      type: require("Game")
    },
    player: {
      default: null,
      type: require("Player")
    },
    jumpAudio: {
      default: null,
      type: cc.AudioClip
    },
    hitAudio: {
      default: null,
      type: cc.AudioClip
    },
    attackBAudio: {
      default: null,
      type: cc.AudioClip
    },
    attackWAudio: {
      default: null,
      type: cc.AudioClip
    },
    hitEff: {
      default: null,
      type: cc.Animation
    }
  }),
  onLoad: function() {
    // 判断是否碰到怪物
    this.isTouch = false;
  },
  // 碰撞检测
  onCollisionStay: function(other, self) {
    this._mstMove = other.getComponent(dragonBones.ArmatureDisplay);

    if (other.tag == 1001) {
      if (this.player._armatureDisPlay.animationName == "atkW01" ||
        this.player._armatureDisPlay.animationName == "atkW02" ||
        this.player._armatureDisPlay.animationName == "atkW03") {
        if (this._mstMove.animationName == "run") {
          this._mstMove.playAnimation('die', 1);
          cc.audioEngine.play(this.attackWAudio);
          this.prefabManager.stopMove(other.node);
          this.game.gainScore(other.node);
          //播放击中特效
          this.hitEff.node.x = other.node.x;
          this.hitEff.play('hit');
          // 平a技能开启
          this.game._isLeft = true;
          this.game._isRight = true;
          this.isTouch = true;
          console.log('111');
          this.game.comboNum += 1;
          this.game.comboAnm.play();
          this.game.comboDisplay.string = this.game.comboNum.toString();
        }
      }
      else if (
        this.player._armatureDisPlay.animationName == "skill" ||
        this.player._armatureDisPlay.animationName == "s2begin" ||
        this.player._armatureDisPlay.animationName == "s2loop" ||
        this.player._armatureDisPlay.animationName == "s2end") {
        if (this._mstMove.animationName == "run") {
          this._mstMove.playAnimation('die', 1);
          cc.audioEngine.play(this.attackWAudio);
          this.prefabManager.stopMove(other.node);
          this.game.gainScore(other.node);
          //播放击中特效
          this.hitEff.node.x = other.node.x;
          this.hitEff.play('hit');
          this.game.comboNum += 1;
          this.game.comboAnm.play();
          this.game.comboDisplay.string = this.game.comboNum.toString();
          console.log('222');
        }
      }
    } else if (other.tag == 1002) {
      if (this.player._armatureDisPlay.animationName == "atkB01" ||
        this.player._armatureDisPlay.animationName == "atkB02" ||
        this.player._armatureDisPlay.animationName == "atkB03") {
        if (this._mstMove.animationName == "run") {
          this._mstMove.playAnimation('die', 1);
          cc.audioEngine.play(this.attackBAudio);
          this.prefabManager.stopMove(other.node);
          this.game.gainScore(other.node);
          //播放击中特效
          this.hitEff.node.x = other.node.x;
          this.hitEff.play('hit');
          // 平a技能开启
          this.game._isLeft = true;
          this.game._isRight = true;
          this.isTouch = true;
          console.log('333');
          this.game.comboNum += 1;
          this.game.comboAnm.play();
          this.game.comboDisplay.string = this.game.comboNum.toString();
        }
      }
      else if (
        this.player._armatureDisPlay.animationName == "skill" ||
        this.player._armatureDisPlay.animationName == "s2begin" ||
        this.player._armatureDisPlay.animationName == "s2loop" ||
        this.player._armatureDisPlay.animationName == "s2end") {
        if (this._mstMove.animationName == "run") {
          this._mstMove.playAnimation('die', 1);
          cc.audioEngine.play(this.attackBAudio);
          this.prefabManager.stopMove(other.node);
          this.game.gainScore(other.node);
          //播放击中特效
          this.hitEff.node.x = other.node.x;
          this.hitEff.play('hit');
          this.game.comboNum += 1;
          this.game.comboAnm.play();
          this.game.comboDisplay.string = this.game.comboNum.toString();
          console.log('444');
        }
      }
    }


    // if (other.tag == 1001) {
    //   if (this.player._armatureDisPlay.animationName == "atkW01" ||
    //     this.player._armatureDisPlay.animationName == "atkW02" ||
    //     this.player._armatureDisPlay.animationName == "atkW03" ||
    //     this.player._armatureDisPlay.animationName == "skill" ||
    //     this.player._armatureDisPlay.animationName == "s2begin" ||
    //     this.player._armatureDisPlay.animationName == "s2loop" ||
    //     this.player._armatureDisPlay.animationName == "s2end") {
    //     if (this._mstMove.animationName == "run") {
    //       this._mstMove.playAnimation('die', 1);
    //       cc.audioEngine.play(this.attackWAudio);
    //       this.prefabManager.stopMove(other.node);
    //       this.game.gainScore();
    //       //播放击中特效
    //       this.hitEff.node.x = other.node.x;
    //       this.hitEff.play('hit');
    //       // 平a技能开启
    //       this.game._isLeft = true;
    //       this.game._isRight = true;
    //       this.isTouch = true;
    //       // this.player.comboCount();
    //     }
    //   }
    // } else if (other.tag == 1002) {
    //   if (this.player._armatureDisPlay.animationName == "atkB01" ||
    //     this.player._armatureDisPlay.animationName == "atkB02" ||
    //     this.player._armatureDisPlay.animationName == "atkB03" ||
    //     this.player._armatureDisPlay.animationName == "skill" ||
    //     this.player._armatureDisPlay.animationName == "s2begin" ||
    //     this.player._armatureDisPlay.animationName == "s2loop" ||
    //     this.player._armatureDisPlay.animationName == "s2end") {
    //     if (this._mstMove.animationName == "run") {
    //       this._mstMove.playAnimation('die', 1);
    //       cc.audioEngine.play(this.attackBAudio);
    //       this.prefabManager.stopMove(other.node);
    //       this.game.gainScore();
    //       //播放击中特效
    //       this.hitEff.node.x = other.node.x;
    //       this.hitEff.play('hit');
    //       // 平a技能开启
    //       this.game._isLeft = true;
    //       this.game._isRight = true;
    //       this.isTouch = true;
    //       // this.player.comboCount();
    //     }
    //   }
    // }
  },
});
module.exports = ColliderRange;